package com.dianyingyuyue.service;
import com.dianyingyuyue.entity.Plan;
import com.dianyingyuyue.entity.PlanOrder;
import com.dianyingyuyue.util.JdbcUtil;

import java.util.List;

public class PlanOrderService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into planorder(userid,uname,pid,pname,odate,status,ctime) values(?,?,?,?,?,'1',now()) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<PlanOrder> getListAll(int page, int rows, PlanOrder obj) {
        String sql="select * from planorder where 1=1 ";
        if(obj.getPname()!=null&&!obj.getPname().equals("")){
            sql+=" and pname like '%"+obj.getPname()+"%' ";
        }
        if(obj.getUserid()!=0){
            sql+=" and userid= '"+obj.getUserid()+"' ";
        }
        sql+=" limit "+page+","+rows;
        List<PlanOrder> dblist= JdbcUtil.executeQuery(sql,null,PlanOrder.class);
        return dblist;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(PlanOrder obj) {
        String sql="select * from planorder where 1=1 ";
        if(obj.getPname()!=null&&!obj.getPname().equals("")){
            sql+=" and pname like '%"+obj.getPname()+"%' ";
        }
        if(obj.getUserid()!=0){
            sql+=" and userid= '"+obj.getUserid()+"' ";
        }
        List<PlanOrder> memberList= JdbcUtil.executeQuery(sql,null,PlanOrder.class);
        return memberList.size();
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update planorder set status=2 where id=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param id
     * @return
     */
    public PlanOrder getId(String id) {
        String sql="select * from planorder where id="+id;
        List<PlanOrder> users= JdbcUtil.executeQuery(sql,null,PlanOrder.class);
        return users.get(0);
    }


}
